import {url,axios} from '.';

export const getRoleById = async (id) => {
    let res = await axios({
        method: 'get',
        url: `${url}/roles/${id}`
    });
    return res.data;
}

export const listRole = async (current,pageSize) => {
    let res = await axios({
        method: 'get',
        url: `${url}/roles`,
        params: {
            current,pageSize
        }
    });
    return res.data;
}


export const listRoleFunction = async (id) => {
    let res = await axios({
        method: 'get',
        url: `${url}/roles/functions/${id}`
    });
    return res.data;
}
export const assignRoleFunction = async (id,functionIds) => {
    let res = await axios({
        method: 'put',
        url: `${url}/roles/assignFunction/${id}`,
        data:{
            functionIds
        }
    });
    return res.data;
}

export const addRole = async (role) => {
    let res = await axios({
        method: 'post',
        url: `${url}/roles`,
        data:{...role}
    });
    return res.data;
}

export const updateRole = async (role) => {
    let res = await axios({
        method: 'put',
        url: `${url}/roles/${role.id}`,
        data:{...role}
    });
    return res.data;
}

export const deleteRole = async (id) => {
    let res = await axios({
        method: 'delete',
        url: `${url}/roles/${id}`
    });
    return res.data;
}